#ifndef _CCTROLPOINTCAMERA_H_
#define _CCTROLPOINTCAMERA_H_

#include "CGlobals.h"
#include "ISceneNodeAnimator.h"
#include "plane3d.h"
#include "position2d.h"
#include <vector>

class CSceneObject;

class ControlPointCamera
{
public:
	ControlPointCamera();
	~ControlPointCamera(){};

	bool OnEvent (const SEvent& event);


	void setCamCtrlPointObject(CSceneObject* object, ICameraSceneNode* pCamera);
	void resetCameraFromObjectData();
	void saveToCamCtrlPointObject();

	void updateCamera(ICameraSceneNode* pCameraNode);	

	CSceneObject* getCtrlPointObj() { return m_camCtrlPointObj; }

private:
	CSceneObject* m_camCtrlPointObj;	

	irr::core::vector3df m_camDir;
	irr::f32 m_camDis;
	irr::core::vector3df m_targetOffset;
	irr::f32 m_targetHeightOff;

	float m_yaw, m_pitch, m_roll;

	irr::core::vector3df m_ctrlPointPos;
	irr::f32 m_camHeight;

	void computePlane();
	void correctTarget();
	bool m_hasPlane;
	irr::core::plane3df m_areaBasePlane;

	irr::core::position2di m_mouseStartPos;
	bool m_leftMousePressed;
	bool m_rightMousePressed;

	void setAttribute (const c8* attribute, float value);	
	float getAttribute (const c8* attribute);
	

	ICameraSceneNode* m_camera;
};

class CCtrolPointCameraAnimator : public ISceneNodeAnimator
{
public:
	CCtrolPointCameraAnimator (ICameraSceneNode* camera);

	bool isEventReceiverEnabled () const;
	bool OnEvent (const SEvent& event);

	void animateNode (ISceneNode* node, u32 timeMs);

	virtual ISceneNodeAnimator* createClone(ISceneNode* node,
				ISceneManager* newManager=0){ return 0; }

	void initControlPointCameras(CSceneObject* ccpObjSelected);
	void freeControlPointCameras();

	irr::scene::ISceneNode* getCurrentControlPointNode();

	void resetCurrentControlPointCamera();
	void saveToCamCtrlPointObjects();

private:		
	ICameraSceneNode* m_camera;

	std::vector<ControlPointCamera*> m_controlPointCameras;
	int m_currentControlPointCameraIdx;

	void addControlPointCamera(CSceneObject* ccpObj);
	
};

#endif //_CCTROLPOINTCAMERA_H_
